// app.js
// app.js
App({
  onLaunch() {
    // 展示本地存储能力
    var self=this;
   
    this.globalData.updateStatus=1;
    const capsule = wx.getMenuButtonBoundingClientRect();
    
    console.log(capsule);
  
    wx.getSystemInfo({
      success: function(res) {
        console.log(res);
        if (res.screenHeight - res.windowHeight - res.statusBarHeight - 32 > 72) {
          self.globalData.isFullSucreen = true
        }
        let navHeight = res.statusBarHeight
        if(res.platform == 'ios' || res.platform=='devtools'){
          self.globalData.platform = 'ios';
          
        }else if(res.platform == 'android'){
          self.globalData.platform = 'android';
        }
        self.globalData.pixelRatio = res.pixelRatio;
        self.globalData.navHeight = capsule.height;
        self.globalData.navTitleTop = capsule.top;
        self.globalData.statusBarHeight=res.statusBarHeight;
        self.globalData.windowHeight=res.windowHeight;
        self.globalData.screenHeight=res.screenHeight;
        self.globalData.windowWidth=res.windowWidth-2;
        self.globalData.screenWidth=res.screenWidth-2;
        self.globalData.safeHeight = res.safeArea.height; 
        
      }
    })


  },
  autoUpdate:function(){
    var that = this;
    return new Promise(function(resolve, reject) {
      if(wx.canIUse('getUpdateManager')){//获取小程序更新机制兼容 
       const updateManager=wx.getUpdateManager();
      //判断改小程序是否有新版本
      updateManager.onCheckForUpdate(function(res){
        //如果有新版本，更新
        if(res.hasUpdate){
          //准备更新
          updateManager.onUpdateReady(function(){
            wx.showModal({
              title:'更新提示',
              content:'新版本已经准备好，是否重启应用？',
            success:function(res){
              if(res.confirm){
                  updateManager.applyUpdate();
                   resolve('update')          
              }else if(res.cancel){
                console.log("do not update");
                resolve('do not update');                
              }
            }
            })
          })
          updateManager.onUpdateFailed(function(){
            wx.showModal({
              title:'更新失败',
              content:'新版本已经上线啦~，请您删除当前小程序，重新搜索打开哟'
            })
          })          
        }else{
         //console.log('=====>no update');
         resolve('=====>no update');
        }
      })
      }
    })
  },
  goto(url,index='#'){
    console.log(url);
     if(url!='#'){
      if(index=="index"){
          wx.reLaunch({
            url: url,
          })
      }else{
          wx.navigateTo({
            url: url,
          })
      }
     }
  },
  showModals:function(msg,url,index){
    let that = this;
    wx.showModal({
        title: '系统提示',
        content:msg,
        success:function(res){
          console.log(res)
           if(res.confirm){
             that.goto(url,index);
           }
           if(res.cancel){

           }
        }
    })
  },
  globalData: {
    userInfo: null,
    domain:'https://wash.0159.cn/',

  }
})
